//封装axios的配置
import axios from 'axios'
// import { serverUrl } from './common';
const request = axios.create({
    baseURL:'/api',
    timeout:10000,
})

request.interceptors.request.use(function(config){
   
    if(sessionStorage.getItem('user')){
        let user = JSON.parse(sessionStorage.getItem('user'));
        config.headers.Authorization = 'Bearer '+user.token; //请求头添加token
    }
    return config; //请求成功
},function(error){
    return Promise.reject(error); //请求失败
});

request.interceptors.response.use(function(response){

    // console.log(response);
    
    return response.data; //响应成功; 
},function(error){
    return Promise.reject(error); //响应失败
});

export default request;
